#!/bin/bash

yum install -y python
pip install numpy onnx
# 测试 onnx2ncnn 转换工具
echo "Testing onnx2ncnn..."

# 创建临时目录
tmp_dir=$(mktemp -d)
cd "$tmp_dir" || exit 1

# 生成微型 ONNX 模型 (使用 Python)
cat << EOF > test_onnx.py
import numpy as np
from onnx import helper, TensorProto, save

# 创建微型模型 (1x1 输入 -> 输出)
input = helper.make_tensor_value_info('input', TensorProto.FLOAT, [1, 1])
output = helper.make_tensor_value_info('output', TensorProto.FLOAT, [1, 1])

node = helper.make_node('Identity', ['input'], ['output'], name='identity_node')
graph = helper.make_graph([node], 'test_graph', [input], [output])
model = helper.make_model(graph, producer_name='onnx2ncnn-test')

save(model, 'test_model.onnx')
EOF

# 生成 ONNX 模型
python test_onnx.py

# 尝试转换模型
if onnx2ncnn test_model.onnx test_model.param test_model.bin > /dev/null 2>&1; then
    echo "✅ onnx2ncnn test PASSED"
    echo "test scripts success"
    # 检查输出文件
    if [[ -f "test_model.param" && -f "test_model.bin" ]]; then
        echo "   Output files created successfully"
    else
        echo "   ❗ Error: Output files missing"
    fi
else
    echo "❌ onnx2ncnn test FAILED"
    echo "   Check if onnx2ncnn is in your PATH"
fi

# 清理
cd - > /dev/null
rm -rf "$tmp_dir"
